package controller

import (
	"mytest/database"
	"mytest/flower-order/model"
)

const (
	HOLIDAY_TYPE = "holiday_type"
)

var configMap map[string]string

func GetAllConfig() map[string]string {
	if configMap == nil {
		configMap = make(map[string]string)
		var configList []*model.Config
		database.DB.Debug().Model(model.Config{}).Find(&configList)
		for _, v := range configList {
			configMap[v.Name] = v.Value
		}
	}
	return configMap
}

func GetConfigByKey(key string) string {
	if configMap == nil {
		configMap = make(map[string]string)
		var configList []*model.Config
		database.DB.Debug().Model(model.Config{}).Find(&configList)
		for _, v := range configList {
			configMap[v.Name] = v.Value
		}
	}
	if value, ok := configMap[key]; ok {
		return value
	}
	return ""
}
